package com.zhaoxi.project.cms.type.service.impl;

import java.util.List;
import com.zhaoxi.common.utils.DateUtils;
import com.zhaoxi.project.cms.blog.mapper.CmsBlogTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhaoxi.project.cms.type.mapper.CmsTypeMapper;
import com.zhaoxi.project.cms.type.domain.CmsType;

/**
 * 分类信息Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-07-27
 */
@Service
public class CmsTypeServiceImpl
{
    @Autowired
    private CmsTypeMapper cmsTypeMapper;

    @Autowired
    private CmsBlogTypeMapper cmsBlogTypeMapper;

    /**
     * 查询分类信息
     *
     * @param typeId 分类信息主键
     * @return 分类信息
     */

    public CmsType selectCmsTypeByTypeId(Long typeId)
    {
        return cmsTypeMapper.selectCmsTypeByTypeId(typeId);
    }

    /**
     * 查询分类信息列表
     *
     * @param cmsType 分类信息
     * @return 分类信息
     */

    public List<CmsType> selectCmsTypeList(CmsType cmsType)
    {

        List<CmsType> cmsTypeList = cmsTypeMapper.selectCmsTypeList(cmsType);
        for (CmsType type : cmsTypeList) {
            int blogNum = cmsBlogTypeMapper.countBlogByTypeId(type.getTypeId());
            type.setBlogNum(blogNum);
        }
        return cmsTypeList;
        //return cmsTypeMapper.selectCmsTypeList(cmsType);
    }

    /**
     * 新增分类信息
     *
     * @param cmsType 分类信息
     * @return 结果
     */

    public int insertCmsType(CmsType cmsType)
    {
        cmsType.setCreateTime(DateUtils.getNowDate());
        return cmsTypeMapper.insertCmsType(cmsType);
    }

    /**
     * 修改分类信息
     *
     * @param cmsType 分类信息
     * @return 结果
     */

    public int updateCmsType(CmsType cmsType)
    {
        cmsType.setUpdateTime(DateUtils.getNowDate());
        return cmsTypeMapper.updateCmsType(cmsType);
    }

    /**
     * 批量删除分类信息
     *
     * @param typeIds 需要删除的分类信息主键
     * @return 结果
     */

    public int deleteCmsTypeByTypeIds(Long[] typeIds)
    {
        return cmsTypeMapper.deleteCmsTypeByTypeIds(typeIds);
    }

    /**
     * 删除分类信息信息
     *
     * @param typeId 分类信息主键
     * @return 结果
     */

    public int deleteCmsTypeByTypeId(Long typeId)
    {
        return cmsTypeMapper.deleteCmsTypeByTypeId(typeId);
    }
}
